package io.renren.modules.project.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.modules.project.dao.QulaityMarkDao;
import io.renren.modules.project.entity.QulaityMarkEntity;
import io.renren.modules.project.service.QulaityMarkService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Map;
import java.util.List;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;



@Service("qulaityMarkService")
public class QulaityMarkServiceImpl extends ServiceImpl<QulaityMarkDao, QulaityMarkEntity> implements QulaityMarkService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String)params.get("key");

        Page<QulaityMarkEntity> page = this.selectPage(
                new Query<QulaityMarkEntity>(params).getPage(),
                new EntityWrapper<QulaityMarkEntity>().like(StringUtils.isNotBlank(key),"id", key)
        );

        return new PageUtils(page);
    }

    @Override
    public List<QulaityMarkEntity> queryList(Map<String, Object> params){
        List<QulaityMarkEntity> list = this.selectList(
                new EntityWrapper<QulaityMarkEntity>().orderBy("quality_cate",true)
                .orderBy("type",true)
        );
        return list;
    }

    @Override
    public List<QulaityMarkEntity> groupList(Map<String, Object> params){
        List<QulaityMarkEntity> list = this.selectList(
                new EntityWrapper<QulaityMarkEntity>().groupBy("quality_cate,score_radio,type")
                        .orderBy("quality_cate",true)
                        .orderBy("type",true)
        );
        return list;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(QulaityMarkEntity entity) {
        this.insert(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(QulaityMarkEntity entity) {
        this.updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long[] Ids) {
        //删除
        this.deleteBatchIds(Arrays.asList(Ids));
    }

}